﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class DAO_DiaDiem
    {
        //property
        SqlConnection con = new SqlConnection(@"Data Source=JACK-LT\JACK_SERVER;Initial Catalog=QLDD;Integrated Security=True");
        private HashSet<DTO_DiaDiem> listDD = new HashSet<DTO_DiaDiem>();
        //method
        public HashSet<DTO_DiaDiem> DAO_loadDiaDiem(string query = "select * from DiaDiem")
        {           
            SqlDataAdapter da = new SqlDataAdapter();//chứa data
            da.SelectCommand = new SqlCommand(query, con);
            DataTable dt = new DataTable();
            da.Fill(dt); //đổ data vào datatable
            //ném data vào khung DTO
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DTO_DiaDiem dd = new DTO_DiaDiem();
                dd.Madd = dt.Rows[i][0].ToString();            
                dd.Tendd = dt.Rows[i][1].ToString();
                dd.Manoi = dt.Rows[i][2].ToString();
                listDD.Add(dd);
            }

            return listDD;
        }
    }
}
